//
//  PYPPermissionCheck.swift
//  HuaDaoPeifu
//
//  Created by Erickson on 16/4/6.
//  Copyright © 2016年 paiyipai. All rights reserved.
//

import UIKit
import Photos

class PYPPermissionCheck: NSObject {


    class func checkPhotoLibraryPermission(_ handler: @escaping (PHAuthorizationStatus) -> Void){
        let status = PHPhotoLibrary.authorizationStatus()
        switch status {
        case .authorized:
            handler(.authorized)
        case .denied, .restricted :
            
            handler(.restricted)
        case .notDetermined:
            
            PHPhotoLibrary.requestAuthorization() { (status) -> Void in
                switch status {
                case .authorized:
                    
                    DispatchQueue.main.async(execute: {
                        handler(.authorized)
                    })
                    
                case .denied, .restricted:
                    handler(.restricted)
                    
                case .notDetermined:
                    debugPrint("never gonna happen")
                }
            }
        }
    }
}
